package com.daxue.util.day01;

import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.function.BiFunction;

/**
 * @author daxue0929
 * @date 2022/09/08
 **/
public class TestFunction {

    // 1. 对两个数的操作，并且返回操作结果。
    @Test
    public void biFunctionTest() {
        BiFunction<Integer, Integer, Integer> sumFunction = (a, b) -> a + b;
        compute(12, 3, sumFunction);
    }

    public Integer compute(Integer a, Integer b, BiFunction<Integer, Integer, Integer> biFunction) {
        return biFunction.apply(a, b);
    }


    // 对map的键值对用:连接在一起，放进List中

    public static void main(String[] args){
//        TestFunction testFunction = new TestFunction();
//        testFunction.test002();




    }

    @Test
    public void test002() {
        HashMap<String, String> hashMap = new HashMap<>();
        hashMap.put("test1", "dasd");
        hashMap.put("test2", "dasd");

        // 如果存在就计算,要是可变的mqp
        String values = hashMap.computeIfPresent("test1", (key, value)->{
            StringBuffer buffer = new StringBuffer();
            return buffer.append(key).append(":").append(value).toString();
        });
        System.out.println(values);

    }

    public String biApply(String key, Object value) {
        return "";
    }

    public String connect(String key, Object value ,BiFunction<String, Object, String> biFunction) {
        return biFunction.apply(key, value);
    }


}
